<template>
  <div class="login-container">
    <div class="login-form">
      <div class="title-container">
        <img
          src="https://likede2-admin.itheima.net/img/logo.595745bd.png"
          alt=""
        >
      </div>
      <el-form
        ref="form"
        :model="loginForm"
        :rules="loginRules"
        auto-complete="on"
        label-position="left"
      >
        <el-form-item prop="loginName">
          <el-input
            v-model="loginForm.loginName"
            placeholder="请输入用户名"
            name="loginName"
            type="text"
            tabindex="1"
            prefix-icon="el-icon-mobile"
          />
        </el-form-item>

        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            type="password"
            placeholder="请输入密码"
            name="password"
            tabindex="2"
            prefix-icon="el-icon-lock"
            show-password
          />
        </el-form-item>

        <el-form-item>
          <el-input v-model="loginForm.code" prefix-icon="el-icon-headset" />
          <div class="picture">
            <img
              ref="vcimg"
              src="https://likede2-admin.itheima.net/likede/api/user-service/user/imageCode/aaaaa"
              alt=""
            >

            <!--  @click="getNewpic"-->
          </div>
        </el-form-item>

        <el-button
          type="primary"
          style="width: 100%; margin-bottom: 30px"
          @click="submit"
        >登录</el-button>
        <div class="gentleReminder">
          仅用于IT培训教学使用，为保障您的个人信息安全，请勿向平台录入任何个人敏感信息（如手机号、身份证号等）！
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import { isDev } from '@/utils'
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        loginName: isDev ? 'demo' : '',
        password: isDev ? '888itcast.CN764%...' : '',
        code: '',
        clientToken: 'aaaaa',
        loginType: 0
      },
      loginRules: {
        username: [
          { required: true, message: '用户名不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },

  methods: {
    async submit() {
      await this.$refs.form.validate()
      await this.$store.dispatch(`user/handleLogin`, this.loginForm)
      this.$router.push(`/`)
    }
    // getNewpic() {
    //   this.$refs.vcimg.src = 'https://likede2-admin.itheima.net/likede/api/user-service/user/imageCode/' + Math.random()
    // }
  }
}
</script>

<style lang="scss" scoped>
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  width: 100%;
  height: 100%;
  background: url("https://likede2-admin.itheima.net/img/background.be4fae7d.png")
    no-repeat center / cover;
  overflow: hidden;
  // display: flex;
  // justify-content: center;
  // align-items: center;
  .login-form {
    background-color: #fff;
    // position: relative;
    position: absolute;
    width: 518px;
    height: 450px;
    top: 50%;
    left: 50%;
    margin-top: -225px;
    margin-left: -259px;
    box-shadow: 0 3px 70px 0 rgba(30,111,72,.35);
    // max-width: 100%;
    padding: 96px 35px 0px;
    border-radius: 10px;
    .title-container {
      position: relative;
      img {
        position: absolute;
        top: -140px;
        left: 50%;
        margin-left: -48px;
        width: 96px;
        height: 96px;
      }
    }
    // .el-form-item {
    //   width: 100%;
    //   height: 52px;
    //   margin-bottom: 24px;
    //   background: #fff;
    //   border: 1px solid #e2e2e2;
    //   border-radius: 4px;
    // }

    .picture {
      position: absolute;
      top: 0;
      right: 0;
      img {
        height: 40px;
      }
    }
    .gentleReminder {
      padding-top: 20px;
      line-height: 20px;
      font-size: 14px;
      color: #fd3333;
    }
  }
}
</style>
